package com.taomu.app.zongchouhuli.moudle.mine.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.taomu.app.zongchouhuli.R;
import com.taomu.app.zongchouhuli.framework.BaseActivity;
import com.taomu.app.zongchouhuli.moudle.mine.contract.ModifyPhoneContract;
import com.taomu.app.zongchouhuli.moudle.mine.contract.impl.ModifyPhonePresenter;

public class UserChangedPhoneActivity extends BaseActivity<ModifyPhoneContract.Presenter> implements ModifyPhoneContract.View {

    private ImageView mBackIm;

    private EditText mPhoneEt;

    private TextView mSmsTv;

    private EditText mSmsEt;

    private TextView mNextTv;

    @Override
    protected int getContentLayout() {
        return R.layout.activity_change_phone;
    }

    @Override
    protected void initView() {
        mBackIm = findViewById(R.id.modify_old_phone_back_im);
        mNextTv = findViewById(R.id.modify_old_phonoe_next_et);
        mPhoneEt = findViewById(R.id.modify_old_phonoe_phone_et);
        mSmsEt = findViewById(R.id.modify_old_phonoe_sms_et);
        mSmsTv = findViewById(R.id.modify_old_phonoe_sms_tv);
    }

    @Override
    protected void initData() {
        mPresenter.isSmsCanClick(mPhoneEt);
        mPresenter.isNextCanClick(mPhoneEt,mSmsEt);
    }

    @Override
    protected void initEvent() {
        mBackIm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mSmsTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.getSmsCode(getPhone());
            }
        });
        mNextTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.submit(getPhone(), getSms());
            }
        });
    }

    @Override
    protected ModifyPhoneContract.Presenter createPresenter() {
        return new ModifyPhonePresenter(this);
    }

    @Override
    public void setSmsCanClick(int textcolor, boolean enable) {
        mSmsTv.setTextColor(getResources().getColor(textcolor));
        mSmsTv.setEnabled(enable);
    }

    @Override
    public void setNextCanClick(int bgcolor, boolean enable) {
        mNextTv.setEnabled(enable);
        mNextTv.setBackgroundResource(bgcolor);
    }

    @Override
    public void setBackTime(String text, boolean ennable) {
        mSmsTv.setEnabled(ennable);
        mSmsTv.setText(text);
    }

    @Override
    public void setSendSmsSuccess(String msg) {
        showToast(msg);
    }

    @Override
    public void submitSuccess(String msg) {
        showToast(msg);
        startActivity(UserChangedPhoneConfirmActivity.class);
        finish();
    }

    @Override
    protected void onDestroy() {
        mPresenter.onDetch();
        super.onDestroy();
    }

    private String getPhone(){
        return mPhoneEt.getText().toString();
    }

    private String getSms(){
        return mSmsEt.getText().toString();
    }

    @Override
    public void setPresenter(ModifyPhoneContract.Presenter presenter) {

    }
}
